namespace Vanilla.UI

import System

// FRAME
class Frame (Box):
	// ALIGN
	enum Align:
		Left
		Right
		Top
		Bottom
		Fill

	public Alignment as Align = Align.Fill

	// CHILD
	child as Gadget
	Child as Gadget:
		get:
			return child
		set:
			child = value
			Add(value)
	
	// SIZE
	override MinSize as Size:
		get:
			return super() if Child == null
			return Size(Spacing*2,Spacing*2) if Child == null
			return Size(Child.MinSize.Width + Spacing*2, Child.MinSize.Height + Spacing*2)
	
	override MaxSize as Size:
		get:
			return super() if Child == null
			if Expand:
				return Size(Child.MaxSize.Width + Spacing*2, Child.MaxSize.Height + Spacing*2)
			else:
				return MinSize
	
	// ADD
	override def Add (c as Gadget):
		child = c if child == null
		super(c)
	
	// ARRANGE
	override def Arrange ():
		return if Child == null
		
		if Alignment == Align.Fill:
			Child.Rect = Rect(Spacing, Spacing, Rect.Width-Spacing, Rect.Height-Spacing)
		elif Alignment == Align.Left:
			Child.Rect = Rect(Spacing, Spacing, Spacing + Child.MinSize.Width, Rect.Height-Spacing)
		else:
			print "Frame.Arrange() - no code for Alignment ${Alignment}"
		
		//print "me=${Rect} kid=${Child.Rect} align=${Alignment}"
	
	// CONSTRUCTOR
	def constructor (p as Box):
		self(p,Align.Fill,true)
	
	def constructor (p as Box, a as Align, f as bool):
		super(p)
		DrawFrame = f
		Alignment = a
	
	def constructor (p as Box, f as bool):
		self(p, Align.Fill, f)
	
	def constructor (p as Box, a as Align):
		self(p, a, true)

